<template>
  <fragment>
    <template v-for="menu in menus">
      <el-submenu
        :key="menu.id"
        :index="menu.path"
        v-if="!menu.meta.isHidden && menu.children.length"
      >
        <template slot="title">
          <i :class="menu.meta.icon"></i>
          <span slot="title">{{ menu.meta.title }}</span>
        </template>
        <menu-item :menus="menu.children"></menu-item>
      </el-submenu>

      <el-menu-item
        :key="menu.id"
        :index="menu.path"
        v-if="!menu.meta.isHidden && !menu.children.length && !menu.meta.isLink"
      >
        <i :class="menu.meta.icon"></i>
        <span slot="title">{{ menu.meta.title }}</span>
      </el-menu-item>

      <el-menu-item
        :key="menu.id"
        v-if="!menu.meta.isHidden && !menu.children.length && menu.meta.isLink"
      >
        <i :class="menu.meta.icon"></i>
        <a target="_blank" :href="menu.path" class="custom-link">{{
          menu.meta.title
        }}</a>
      </el-menu-item>
    </template>
  </fragment>
</template>

<script>
export default {
  name: "MenuItem",
  props: {
    menus: {
      type: Array,
      required: true,
    },
  },
};
</script>

<style lang="scss" scoped>
.custom-link {
  display: inline-block;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
</style>
